package jwdt.xadmin.work.action;

import jwdt.common.action.BaseAction;
import jwdt.xadmin.work.bean.TProject;
import jwdt.xadmin.work.service.ProjectManageService;

import com.ezerg.db.Jdb;
import com.ezerg.db.ext.PageUtil;
import com.ezerg.web.Form;
import com.ezerg.web.Module;
import com.ezerg.web.Page;
import com.ezerg.web.annotation.Controller;
import com.ezerg.web.annotation.RequestMapping;

@Controller("/xadmin/work")
public class ProjectManagerAction extends BaseAction {
	
	private ProjectManageService projectManageService = (ProjectManageService)app.getBean("projectManageService");
	
	@RequestMapping("/listProject")
	public Page doLisTProject(Form f, Module m) throws Exception {
		PageUtil pu = (PageUtil)f.copy2Class(PageUtil.class);
		TProject obj = (TProject)f.copy2Class(TProject.class);
    	return m.getWritePage(f, projectManageService.doList(pu,obj).toJson());
	}
	
	@RequestMapping("/addProject")
	public Page doAddact(Form f, Module m) throws Exception {
		TProject obj = (TProject)f.copy2Class(TProject.class);
		return m.getWritePage(f, projectManageService.doAddact(obj));
	}
	
	@RequestMapping("/editProject")
	public Page doEditact(Form f, Module m) throws Exception {
		int projectid = f.getInt("projectid");
		TProject obj = (TProject)f.copy2Class(TProject.class);
		return m.getWritePage(f, projectManageService.doEditact(obj, projectid));
	}
	
	@RequestMapping("/delProject")
	public Page doDel(Form f, Module m) throws Exception {
		int projectid = f.getInt("projectid");
		return m.getWritePage(f, projectManageService.doDelact(projectid));
	}
	
	@RequestMapping("/projectWindow")
	public Page doLoad(Form f, Module m) throws Exception {
		int projectid = f.getInt("projectid");
		f.add("obj", projectManageService.doLoad(projectid));
		return m.findPage("/xadmin/work/projectWindow");
	}
	
	@RequestMapping("/listProjectForTree")
	public Page doListProjectForTree(Form f, Module m) throws Exception {
    	return m.getWritePage(f, projectManageService.doListProjectForTree());
	}
	
	@RequestMapping("/listProjectForCombox")
	public Page doListProjectForCombox(Form f, Module m) throws Exception {
    	return m.getJsonPage(f, Jdb.get().query("SELECT projectid,NAME FROM t_project ORDER BY projectid"));
	}
}
